#include "prpsinfotab.h"
#include "prpsfeature.h"
#include <QHeaderView>
#include <QHBoxLayout>
#include <QString>

PRPSInfoTab::PRPSInfoTab(QWidget *parent)
    : MapInfoTab(parent)
    , m_prpsFeature(std::make_shared<PRPSFeature>())
    , m_pChartBox(new QGroupBox("图谱数据"))
    , m_pChartData(new QTextEdit)
    , m_pMainLayout(new QHBoxLayout(this))
    , m_pLayout(new QHBoxLayout(this))
{
    // 创建布局
    m_pLayout->addWidget(m_pChartData);
    m_pChartBox->setLayout(m_pLayout);

    m_pMainLayout->addWidget(m_prpsFeature->initUI(this));
    m_pMainLayout->addWidget(m_pChartBox);

    setLayout(m_pMainLayout);

    // 添加PRPS特性组件
    addFeature(std::dynamic_pointer_cast<IMapInfoFeature>(m_prpsFeature));
}

PRPSInfoTab::~PRPSInfoTab()
{
    delete m_pChartBox;
    delete m_pChartData;
    delete m_pMainLayout;
    delete m_pLayout;
}

void PRPSInfoTab::setDataTypeCode(uint8_t code)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setDataTypeCode(code);
    }
}

void PRPSInfoTab::setDataLength(int32_t length)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setDataLength(length);
    }
}

void PRPSInfoTab::setCreateTime(const QString& time)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setCreateTime(time);
    }
}

void PRPSInfoTab::setChartProperty(const DataSpecificationGW::SpectrumCharacter& property)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setChartProperty(property);
    }
}

void PRPSInfoTab::setDeviceName(const QString& name)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setDeviceName(name);
    }
}

void PRPSInfoTab::setDeviceCode(const QString& code)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setDeviceCode(code);
    }
}

void PRPSInfoTab::setMeasurementName(const QString& name)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setMeasurementName(name);
    }
}

void PRPSInfoTab::setMeasurementCode(const QString& code)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setMeasurementCode(code);
    }
}

void PRPSInfoTab::setChannelFlag(int64_t flag)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setChannelFlag(flag);
    }
}

void PRPSInfoTab::setDataType(uint8_t type)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setDataType(type);
    }
}

void PRPSInfoTab::setAmplitudeUnit(uint8_t unit)
{
    if (m_prpsFeature) {
        m_prpsFeature->setAmplitudeUnit(unit);
    }
}

void PRPSInfoTab::setAmplitudeLowerLimit(float lowerLimit)
{
    if (m_prpsFeature) {
        m_prpsFeature->setAmplitudeLowerLimit(lowerLimit);
    }
}

void PRPSInfoTab::setAmplitudeUpperLimit(float upperLimit)
{
    if (m_prpsFeature) {
        m_prpsFeature->setAmplitudeUpperLimit(upperLimit);
    }
}

void PRPSInfoTab::setFrequencyBand(uint8_t band)
{
    // PRPS不需要处理频带
}

void PRPSInfoTab::setLowerFrequency(float lowerFreq)
{
    // PRPS不需要处理频率
}

void PRPSInfoTab::setUpperFrequency(float upperFreq)
{
    // PRPS不需要处理频率
}

void PRPSInfoTab::setPhaseWindowCount(int32_t count)
{
    if (m_prpsFeature) {
        m_prpsFeature->setPhaseWindowCount(count);
    }
}

void PRPSInfoTab::setQuantizedAmplitude(int n)
{
    // PRPS不需要量化幅值
}

void PRPSInfoTab::setFrequencyPeriod(int32_t num)
{
    if (m_prpsFeature) {
        m_prpsFeature->setFrequencyPeriod(num);
    }
}

void PRPSInfoTab::setDischargeTypeProbability(const QString& probability)
{
    // PRPS不需要处理放电类型概率
}

void PRPSInfoTab::setBackgroundFileName(const QString& fileName)
{
    // PRPS不需要处理背景文件名称
}

void PRPSInfoTab::setReservedData(const QByteArray& byte)
{
    // 数据会通过特性组件显示
    if (m_prpsFeature) {
        m_prpsFeature->setReservedData(byte);
    }
}

void PRPSInfoTab::setPRPSData(const QByteArray& byte)
{
    if (m_prpsFeature) {
        m_prpsFeature->setPRPSData(byte);
    }
    
    // 在图表数据框显示数据的十六进制表示
    m_pChartData->setText(byte.toHex());
}
